import jobLogDao from "#/dao/job/log";
import type { TaskLog, BaseService } from "#/types";
import { getUuid, logger, codeFail, codeSuccess } from "#/utils";
/**
 * Job日志实现类
 */
class JobLogService implements BaseService<TaskLog> {
  async queryList({ page, pageSize, searchContent }) {
    try {
      const r = await jobLogDao.queryList({ page, pageSize, searchContent });
      const rTotal = await jobLogDao.queryTotal("task_name", searchContent);
      if (r) {
        return codeSuccess({
          items: r,
          total: rTotal.length,
        });
      }
      return codeFail("查询失败");
    } catch (error) {
      logger(error);
    }
  }
  async insert(params: TaskLog) {
    try {
      const id = getUuid();
      const d = {
        ...params,
        id,
      };
      await jobLogDao.insert(d);
      return codeSuccess();
    } catch (error) {
      logger(error);
    }
  }
  async deleteById(id: string) {
    return codeSuccess(id);
  }
  async update(params: TaskLog) {
    try {
      await jobLogDao.update({ ...params });
      return codeSuccess();
    } catch (error) {
      logger(error);
    }
  }
}
export default new JobLogService();
